package tw.miku.protocol.codec.user;

import java.nio.charset.CharacterCodingException;

import org.apache.mina.core.buffer.IoBuffer;

import tw.miku.constants.ProtocalConstants;
import tw.miku.model.User;
import tw.miku.protocol.codec.AbstractResponseMessagePack;
import tw.miku.util.BufferUtility;

public class UserOnlineResponsePack extends AbstractResponseMessagePack
{
	public static final byte USER_ONLINE = 0;
	public static final byte USER_OFFLINE = 1;

	public User user;

	@Override
	public IoBuffer encode() throws CharacterCodingException
	{
		IoBuffer buf = BufferUtility.newInstance();
		buf.position(4);  

		buf.putShort(ProtocalConstants.USER_ONLINE);
		buf.putShort((short) 0);
		buf.put(user.getInfo());

		buf.flip();
		buf.putUnsignedInt(buf.limit() - 4);
		buf.position(0);

		// buf.putUnsignedInt(userId);
		// buf.put(status);
		return buf;
	}

	@Override
	public short getTag()
	{
		return ProtocalConstants.USER_ONLINE;
	}

}
